<?php

class EditedReport extends CActiveRecord
{
	/**
	 * The followings are the available columns in table 'edited_report':
	 * @var integer $id
	 * @var integer $report_id
	 * @var string $edition_date
	 * @var string $edition_user
	 * @var string $filename
	 * @var string $type
	 * @var integer $project_id
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return EditedReport the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'edited_report';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('report_id, edition_date, edition_user, filename, type, project_id', 'required'),
			array('report_id, project_id, meeting_id', 'numerical', 'integerOnly'=>true),
			array('edition_user, type', 'length', 'max'=>20),
			array('filename', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, report_id, edition_date, edition_user, filename, meeting_id, type, project_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'project' => array(self::BELONGS_TO, 'Project', 'project_id'),
			'report' => array(self::BELONGS_TO, 'Report', 'report_id'),
			'meeting' => array(self::BELONGS_TO, 'Meetings', 'meeting_id'),
			'parameters' => array(self::HAS_MANY, 'EditedReportParameter', 'edited_report_id', 'index' => 'name'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => Yii::t('database', 'Id'),
			'report_id' => Yii::t('database', 'Report'),
			'meeting_id' => Yii::t('database', 'Meeting'),
			'edition_date' => Yii::t('database', 'Edition Date'),
			'edition_user' => Yii::t('database', 'Edition User'),
			'filename' => Yii::t('database', 'Filename'),
			'type' => Yii::t('database', 'Type'),
			'project_id' => Yii::t('database', 'Project'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);

		$criteria->compare('report_id',$this->report_id);

		$criteria->compare('edition_date',$this->edition_date,true);

		$criteria->compare('edition_user',$this->edition_user,true);

		$criteria->compare('filename',$this->filename,true);

		$criteria->compare('type',$this->type,true);

		$criteria->compare('project_id',$this->project_id);

		$criteria->compare('meeting_id',$this->meeting_id);

		return new CActiveDataProvider('EditedReport', array(
			'criteria'=>$criteria,
		));
	}
}